package com.ytf.test.tenth;

abstract class Base {
    public Base() {
        System.out.println("Base constructor");
    }

    public Base(int i1) {
        System.out.println("Base constructor,i=" + i1);
    }
    public abstract void f();
}
/**
 * @author: YTF
 * @date: 2025/3/6
 * @version: 1.0
 * @description:
 */
public class AnonymousConstructor {
    public static Base getBase(int i) {
        return new Base(i) {
            {
                System.out.println("Inside instance initializer");
            }
            @Override
            public void f() {
                System.out.println("In anonymous f()");
            }
        };
    }
    public static Base getBase() {
        return new Base() {
            {
                System.out.println("Inside instance initializer");
            }
            @Override
            public void f() {
                System.out.println("In anonymous f()");
            }
        };
    }

    public static void main(String[] args) {
        Base b = getBase(47);
        b.f();
        Base b2 = getBase();
        b2.f();
        /**
         * Output:
         * Base constructor,i=47
         * Inside instance initializer
         * In anonymous f()
         */
    }
}
